package com.zt.service.sys.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.zt.dao.sys.ISampleDao;
import com.zt.model.sys.Sample;
import com.zt.rowmapper.sys.SampleMapper;
import com.zt.service.sys.ISampleService;

/**
 * Service 类 SampleService
 * 
 * @author zhangzhw
 * 
 */
@Transactional
public class SampleService implements ISampleService {

	ISampleDao iSampleDao;

	public List<Sample> findSample() throws Exception {

		StringBuffer sb = new StringBuffer();
		sb.append("SELECT SAMPLE_ID,\n");
		sb.append("       SAMPLE_NAME,\n");
		sb.append("       SAMPLE_DATE\n");
		sb.append("  FROM SAMPLE\n");
		sb.append(" ORDER BY SAMPLE_ID DESC\n");

		String sql = sb.toString();

		return iSampleDao.query(sql, new SampleMapper());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.zt.service.sys.impl.ISampleService#save(com.zt.model.sys.Sample)
	 */
	public int save(Sample s) throws Exception {
		return iSampleDao.saveOrUpdate(s);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.zt.service.sys.impl.ISampleService#save(java.util.List)
	 */
	public int save(List<Sample> l) throws Exception {

		int i = 0;

		for (Sample s : l) {
			i += iSampleDao.save(s);
		}

		return i;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.zt.service.sys.impl.ISampleService#delete(com.zt.model.sys.Sample)
	 */
	public int delete(Sample s) throws Exception {

		return iSampleDao.delete(s);

	}

	public ISampleDao getiSampleDao() {
		return iSampleDao;
	}

	public void setiSampleDao(ISampleDao iSampleDao) {
		this.iSampleDao = iSampleDao;
	}

}
